<template>
    <view class="content">
        <image src="../../static/image/s_index.png" class="s-index"></image>
        
        <view class="wrapper">
            <view class="box" v-for="(item, index) in list" :key="index">
                <view class="top">
                    <view class="u-flex-1">
                        <view class="item">
                            <view class="left">运输线路</view>
                            <view class="right">{{item.line}}</view>
                        </view>
                        <view class="item">
                            <view class="left">始发地</view>
                            <view class="right">{{item.origin}}</view>
                        </view>
                    </view>
					<!-- mode=1定向派单模式 2抢单模式 -->
                    <view class="top-r">
						<view class="o-sta2" v-if="item.mode == 1">定向派单模式</view>
                        <view class="o-sta1" v-if="item.mode == 2">抢单模式</view>
                    </view>
                </view>
                <view class="item">
                    <view class="left">目的地</view>
                    <view class="right">{{item.destination}}</view>
                </view>
                <view class="item">
                    <view class="left">装车地点</view>
                    <view class="right">{{item.loading_site}}</view>
                </view>
                <view class="item">
                    <view class="left">车辆类型</view>
                    <view class="right">{{item.vehicle}}</view>
                </view>
                <view class="item">
                    <view class="left">车长要求</view>
                    <view class="right">{{item.length}}</view>
                </view>
                <view class="item">
                    <view class="left">载重要求</view>
                    <view class="right">{{item.load}}</view>
                </view>
                <view class="item" v-if="item.start_date">
                    <view class="left">发车时间</view>
                    <view class="right">{{item.start_date}}</view>
                </view>
                <view class="item" v-if="item.end_date">
                    <view class="left">到达时间</view>
                    <view class="right">{{item.end_date}}</view>
                </view>
                <view class="item" v-if="item.costs">
                    <view class="left">租赁费用</view>
                    <view class="right">{{item.costs}}元</view>
                </view>
                <view class="item" v-if="item.remark">
                    <view class="left">备注</view>
                    <view class="right">{{item.remark}}</view>
                </view>
                
                <view class="btns">
                    <view class="btn1" @click.stop="$noMultipleClicks(receive, item)">接单</view>
                    <view class="btn2" v-if="item.mode == 1" @click.stop="refuse(item)">拒绝</view>
                </view>
            </view>
        
			<view style="height: 94rpx;padding-top: 30rpx;">
			    <u-loadmore :status="status" v-if="status != 'loadmore'" />
			</view>
		</view>
		
		<u-mask :show="show">
		    <view class="privacy-pop">
		        <view class="privacy-pop-box">
		            <view class="close-01">
		                <u-icon name="close-circle" size="50" @click="show = false"></u-icon>
		            </view>
		            <view class="privacy-title">拒绝原因</view>
		            <view>
		                <textarea v-model="content" placeholder="请输入拒绝原因" class="t-inp"></textarea>
		            </view>
		            <view class="btn-text2" @click.stop="confirmRefuse">确定</view>
		        </view>
		    </view>
		</u-mask>
        
        <!-- 底部导航 -->
        <u-tabbar v-model="current" :list="tab_list" active-color="#00457f" inactive-color="#5d5f6a" :border-top="true" @change="tabbarChange"></u-tabbar>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                statusBar: 0,
                background: { backgroundColor: 'rgba(255,255,255,0)' },
                current: 0, //底部导航索引
                tab_list: [],
				noClick:true,//连点
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
				show: false,
				content: '',
				item: {},
            };
        },
        onLoad() {
            let _this = this;
            //状态栏高度
            uni.getSystemInfo({
            	success: function(res) {
            		_this.statusBar = res.statusBarHeight;
            	}
            });
            
            // 接收身份监听
            uni.$on('identityChange', data => {
                this.tabbarInfo();
            })
        },
        onShow() {
            this.tabbarInfo();
			if (this.$getSync('userToken')) {
				this.list = []
				this.page = 1
				this.status = 'loadmore'
				this.getList()
			}
        },
		onReachBottom() {
			if(this.page == 1){return}
			this.getList()
		},
        methods: {
            // 接单
            receive(item) {
				this.$ajax('driver_receiving', {
					user_token: this.$getSync('userToken'),
					status: 1,//1接单 2拒绝 抢单没有拒绝
					order_id: item.id,
				}).then(ret => {
					if (ret.success == 1000) {
						this.$confirm('您的接单需求已提交审核', ()=> {
							this.list = []
							this.page = 1
							this.status = 'loadmore'
							this.getList()
						})
					} else {
						this.$toast(ret.msg);
					}
				});
            },
            
            // 拒绝
            refuse(item) {
				this.item = item
				this.show = true
            },
			confirmRefuse() {
				if (!this.content) {
					this.$toast('请输入拒绝原因')
					return
				}
				this.$ajax('driver_receiving', {
					user_token: this.$getSync('userToken'),
					status: 2,//1接单 2拒绝 抢单没有拒绝
					reason: this.content,//拒绝原因
					order_id: this.item.id,
				}).then(ret => {
					if (ret.success == 1000) {
						this.show = false
						this.$toast('已提交')
						setTimeout(() => {
							this.content = ''
							this.list = []
							this.page = 1
							this.status = 'loadmore'
							this.getList()
						}, 500)
					} else {
						this.$toast(ret.msg);
					}
				});
			},
			
			// 获取司机订单列表
			getList() {
				if (this.status == 'nomore') return;
				this.status = 'loading';
				this.$ajax('driver_orders', {
					user_token: this.$getSync('userToken'),
					page: this.page,
					limit: 10,
				}).then(ret => {
					if (ret.success == 1000) {
						if (ret.detail && ret.detail.orders && ret.detail.orders.length > 0) {
							this.list = this.list.concat(ret.detail.orders);
							this.page++;
							this.status = 'loadmore'
						} else {
							this.status = 'nomore'
						}
					} else {
						this.$toast(ret.msg);
					}
				});
			},
            
            //切换底部导航
            tabbarChange(e) {
            	this.current = e;
            },
            
            tabbarInfo(){
                // 用户
                if (this.$getSync('identity') == 1) {
                    this.tab_list = [
                        {
                            iconPath: "/static/icon/tab_01.png",
                            selectedIconPath: "/static/icon/tab_02.png",
                            text: '发货',
                            pagePath: "/pages/tabbar/index"
                        },{
                            iconPath: "/static/icon/tab_03.png",
                            selectedIconPath: "/static/icon/tab_04.png",
                            text: '订单',
                            pagePath: "/pages/tabbar/order"
                        },{
                            iconPath: "/static/icon/tab_05.png",
                            selectedIconPath: "/static/icon/tab_06.png",
                            text: '我的',
                            pagePath: "/pages/tabbar/mine"
                        }
                    ];
                }
                // 司机
                if(this.$getSync('identity') == 2){
                    this.tab_list = [
                        {
                            iconPath: "/static/icon/tab_01.png",
                            selectedIconPath: "/static/icon/tab_02.png",
                            text: '首页',
                            pagePath: "/pages/tabbar/driver"
                        },{
                            iconPath: "/static/icon/tab_05.png",
                            selectedIconPath: "/static/icon/tab_06.png",
                            text: '我的',
                            pagePath: "/pages/tabbar/driver-mine"
                        }
                    ];
                }
            },
            
            onPageScroll: function(e) {
            	//nvue暂不支持滚动监听，可用bindingx代替
            	// console.log("滚动距离为：" + e.scrollTop);
            	let a = e.scrollTop * 0.05;
            	if (a > 1) {
            		a = 1;
            	}
            	if (e.scrollTop == 0) {
            		this.background.backgroundColor = 'rgba(255,255,255,0)';
            	} else {
            		this.background.backgroundColor = 'rgba(255,255,255,' + a + ')';
            	}
            },
        }
    };
</script>

<style lang="scss">
	.privacy-pop {
	    display: flex;
	    align-items: center;
	    justify-content: center;
	    height: 100%;
	}
	.privacy-pop-box {
	    width: 700rpx;
	    padding: 40rpx 20rpx 20rpx;
	    background-color: #fff;
	    box-sizing: border-box;
	    border-radius: 20rpx;
	    position: relative;
	}
	.close-01{
	    position: absolute;
	    right: 20rpx;
	    top: 20rpx;
	}
	.privacy-title {
	    font-size: 32rpx;
	    font-weight: bold;
	    text-align: center;
	    padding: 20rpx 0 40rpx;
	}
	.t-inp{
	    width: 100%;
	    background-color: #f5f6fa;
	    border-radius: 10rpx;
	    padding: 20rpx;
	}
	.btn-text2{
	    font-size: 30rpx;
	    color: #fff;
	    background-color: #00457f;
	    padding: 20rpx 50rpx;
	    border-radius: 20rpx;
	    margin: 20rpx;
	    text-align: center;
	}
	
    page{
        background: linear-gradient(to bottom, #e8f0fd, #edf3ff);
    }
    .s-index{
        width: 750rpx;
        height: 425rpx;
    }
    .wrapper{
        padding: 20rpx;
        margin-top: -20rpx;
    }
    .box{
        background-color: #fff;
        border-radius: 15rpx;
        padding: 40rpx 30rpx 30rpx;
        margin-bottom: 16rpx;
    }
    .top{
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 10rpx;
    }
    .left{
        width: 140rpx;
        color: #656565;
    }
    .right{
        flex: 1;
        word-break: break-all;
        white-space: pre-line;
    }
    .top-r{
        display: flex;
        flex-direction: column;
        align-items: flex-end;
    }
    .o-sta{
        font-size: 24rpx;
        color: #ff602c;
        padding-bottom: 10rpx;
        padding-left: 10rpx;
    }
    .o-sta1{
        font-size: 24rpx;
        color: #ff5400;
        padding: 7rpx 15rpx;
        background-color: #fff;
        border: 2rpx solid #ff5400;
        box-sizing: border-box;
        border-radius: 10rpx;
        margin-left: 10rpx;
        margin-bottom: 10rpx;
    }
    .o-sta2{
        font-size: 24rpx;
        color: #0075ff;
        padding: 7rpx 15rpx;
        background-color: #ebf4fe;
        border-radius: 10rpx;
        margin-left: 10rpx;
        margin-bottom: 10rpx;
    }
    .price{
        font-size: 26rpx;
        color: #ff602c;
    }
    .price-num{
        font-size: 38rpx;
    }
    .btns{
        padding-top: 10rpx;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        color: #fff;
    }
    .btn1{
        padding: 15rpx 50rpx;
        background-color: #004580;
        border-radius: 50rpx;
        margin-left: 20rpx;
    }
    .btn2{
        padding: 15rpx 50rpx;
        background-color: #9aafc2;
        border-radius: 50rpx;
        margin-left: 20rpx;
    }
    .btn3{
        padding: 15rpx 25rpx;
        background-color: #fff;
        border-radius: 50rpx;
        margin-left: 20rpx;
        color: #004580;
        border: 2rpx solid #004580;
        box-sizing: border-box;
    }

</style>
